home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_force_project.cog < prev    next >
Text File  |  1998-02-25  |  6KB  |  260 lines

  1. # Jedi Knight Cog Script
  2. #
  3. # FORCE_PROJECT.COG
  4. #
  5. # FORCEPOWER Script - Projection
  6. #  Bin 36
  7. #
  8. # [YB]
  9. #
  10. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  11.  
  12.  
  13. symbols
  14.  
  15. thing       player                           local
  16.  
  17. flex        cost=50.0                        local
  18. int         rank                             local
  19. flex        mana                             local
  20. model       weaponMesh=fistg.3do             local
  21.  
  22. sound       projSound=FProject.WAV           local
  23. template    projection_tpl=+Projection       local
  24.  
  25. int         projection=-1                    local
  26. flex        randval=0.0                      local
  27. int         strafed=0                        local
  28. int         turned=0                         local
  29.  
  30. int         myMode=-1                        local
  31. int         attachFlags                      local
  32.  
  33. int         inbubble=0                       local
  34.  
  35. message     startup
  36. message     activated
  37. message     newplayer
  38. message     killed
  39. message     selected
  40. message     timer
  41. message     enterbubble
  42. message     exitbubble
  43. message     pulse
  44.  
  45. end
  46.  
  47. # ========================================================================================
  48.  
  49. code
  50.  
  51. startup:
  52.    player = GetLocalPlayerThing();
  53.    inbubble = 0;
  54.    call stop_power;
  55.  
  56.    Return;
  57.  
  58. # ........................................................................................
  59.  
  60. activated:
  61.    if(inbubble) Return;
  62.  
  63.    // Cannot cast underwater...
  64.    if(GetSectorFlags(GetThingSector(player)) & 2) Return;
  65.  
  66.    // Must be attached to a world surface or thing face
  67.    attachFlags = GetAttachFlags(player);
  68.    if(!((attachFlags & 1) || (attachFlags & 2))) Return;
  69.  
  70.    // Must not be crouching
  71.    if(IsThingCrouching(player)) Return;
  72.  
  73.    if((!IsInvActivated(player, 36)) && (GetThingHealth(player) > 0))
  74.    {
  75.       mana = GetInv(player, 14);
  76.       if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  77.       {
  78.          if(GetInv(player, 64) != 1) ChangeInv(player, 14, -cost);
  79.  
  80.          // Send a "force disturbance"...
  81.          if(!IsMulti())
  82.             SendMessageExRadius(GetThingPos(player), cost, 0x4, splash, 36, 0, 0, 0);
  83.  
  84.          SetInvActivated(player, 36, 1);
  85.  
  86.          PlayMode(player, 24);
  87.          PlaySoundThing(projSound, player, 1.0, -1, -1, 0x80);
  88.  
  89.          rank = GetInv(player, 36);
  90.  
  91.          // Create the projection
  92.          projection = CreateThing(projection_tpl, player);
  93.  
  94.          // Assign it the same model
  95.          SetThingModel(projection, GetThingModel(player));
  96.  
  97.          // Add a hand/weapon mesh to the model
  98.          jkSetWeaponMesh(projection, weaponMesh);
  99.  
  100.          // Make it collidable in single player (AI stuff)
  101.          if(!IsMulti()) SetCollideType(projection, 1);
  102.  
  103.          SetTimerEx(8 * rank, 0, 0, 0);
  104.          SetPulse(1);
  105.       }
  106.    }
  107.  
  108.    Return;
  109.  
  110. # ........................................................................................
  111.  
  112. timer:
  113.    call stop_power;
  114.    Return;
  115.  
  116. # ........................................................................................
  117.  
  118. pulse:
  119.    if(projection != -1)
  120.    {
  121.       // stop current anim if any
  122.       if(myMode != -1)
  123.       {
  124.          StopKey(projection, myMode, 0.0);
  125.          myMode = -1;
  126.       }
  127.  
  128.       if(jkGetBubbleDistance(projection) <= 1.0)
  129.       {
  130.          call stop_power;
  131.          Return;
  132.       }
  133.  
  134.       randval = rand();
  135.  
  136.       if(randval < 0.5)
  137.       {
  138.          // do another action quicker after a fire
  139.          SetPulse(0.33);
  140.  
  141.          // Fire
  142.          myMode = PlayMode(projection, 8);
  143.       }
  144.       else
  145.       if(randval < 0.99)
  146.       {
  147.          SetPulse(0.5 + rand());
  148.  
  149.          // if we had a strafe put the character in place
  150.          // we don't want him to move...
  151.          if(strafed)
  152.          {
  153.             // Counterstrafe
  154.             if(strafed == 1)
  155.             {
  156.                myMode = PlayMode(projection, 6);
  157.             }
  158.             else
  159.             {
  160.                myMode = PlayMode(projection, 5);
  161.             }
  162.             strafed = 0;
  163.          }
  164.          else
  165.          if(turned)
  166.          {
  167.             // Counterturn
  168.             if(turned == 1)
  169.             {
  170.                myMode = PlayMode(projection, 32);
  171.             }
  172.             else
  173.             {
  174.                myMode = PlayMode(projection, 31);
  175.             }
  176.             turned = 0;
  177.          }
  178.          // we did not strafe or turn previously, chose an action
  179.          else
  180.          {
  181.             if(rand() < 0.5)
  182.             {
  183.                // turn
  184.                if(rand() < 0.5)
  185.                {
  186.                   myMode = PlayMode(projection, 31);
  187.                   turned = 1;
  188.                }
  189.                else
  190.                {
  191.                   myMode = PlayMode(projection, 32);
  192.                   turned = 2;
  193.                }
  194.             }
  195.             else
  196.             {
  197.                // strafe
  198.                if(rand() < 0.5)
  199.                {
  200.                   myMode = PlayMode(projection, 5);
  201.                   strafed = 1;
  202.                }
  203.                else
  204.                {
  205.                   myMode = PlayMode(projection, 6);
  206.                   strafed = 2;
  207.                }
  208.             }
  209.          }
  210.       }
  211.    }
  212.    Return;
  213.  
  214. # ........................................................................................
  215.  
  216. selected:
  217.    jkPrintUNIString(player, 36);
  218.    Return;
  219.  
  220. # ........................................................................................
  221.  
  222. killed:
  223.    if(GetSenderRef() != player) Return;
  224.  
  225. newplayer:
  226.    call stop_power;
  227.  
  228.    Return;
  229.  
  230. # ........................................................................................
  231.  
  232. enterbubble:
  233.    inbubble = 1;
  234.    call stop_power;
  235.    Return;
  236.  
  237. # ........................................................................................
  238.  
  239. exitbubble:
  240.    inbubble = 0;
  241.    Return;
  242.  
  243. # ........................................................................................
  244.  
  245. stop_power:
  246.    SetPulse(0);
  247.    SetInvActivated(player, 36, 0);
  248.    if(projection != -1)
  249.    {
  250.       DestroyThing(projection);
  251.       projection = -1;
  252.    }
  253.  
  254.    Return;
  255.  
  256. end
  257.  
  258.  
  259.  
  260.